package com.flyiu.data.consistency.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.flyiu.data.consistency.model.DistributedTransactionInstance;
import com.flyiu.data.consistency.model.IdempotentEntity;

public interface IdempotentRepository
		extends JpaRepository<IdempotentEntity, Integer>, JpaSpecificationExecutor<IdempotentEntity> {
	@Query
	IdempotentEntity findByIdemValue(String idemValue);

	@Transactional(propagation = Propagation.REQUIRES_NEW)
	@Modifying
	@Query(value = "update IdempotentEntity set state = :state,response=:response  where id  = :id")
	public int updateIdempotent(@Param(value = "state") String state, @Param(value = "response") String response,
			@Param(value = "id") int id);
}
